import { FormProps } from 'jn-ve-global'
import { useRoute } from 'vue-router'
import type { RouteMeta } from '@jsjn/types/Route'

export default (config: FormProps) => {
    const currentRoute = useRoute()
    // 获取当前路由下的权限列表
    const permissionList = currentRoute?.meta?.btns as RouteMeta['btns']
    if (!permissionList || !permissionList.length) return config

    // 筛选对应的节点
    config.formItems.forEach((formItem) => {
        if (!formItem.authCode) return
        const targetPermission = permissionList?.find(
            (permissionItem) => permissionItem.perms === formItem.authCode
        )
        if (!targetPermission) return
        formItem.hide = !targetPermission.btnCheck
    })

    // 返回处理过的表单配置
    return config
}
